const fs = require('fs');
const path = require('path');

// 读取文件内容
const filePath = path.join(__dirname, 'entry', 'src', 'main', 'ets', 'features', 'patient', 'MedicineReminderPage.ets');
try {
  const content = fs.readFileSync(filePath, 'utf-8');
  console.log('文件读取成功，长度:', content.length, '字符');
  
  // 基本语法检查 - 括号匹配
  const brackets = { '(': ')', '{': '}', '[': ']' };
  const stack = [];
  let isValid = true;
  
  for (let i = 0; i < content.length; i++) {
    const char = content[i];
    if (brackets[char]) {
      stack.push(char);
    } else if (Object.values(brackets).includes(char)) {
      const last = stack.pop();
      if (!last || brackets[last] !== char) {
        isValid = false;
        console.log(`语法错误: 括号不匹配在位置 ${i}, 字符 '${char}'`);
        break;
      }
    }
  }
  
  if (stack.length > 0) {
    isValid = false;
    console.log(`语法错误: 未闭合的括号: ${stack.join(', ')}`);
  }
  
  if (isValid) {
    console.log('基本语法检查通过 - 括号匹配正常');
  }
  
  // 检查@Builder、@Component等装饰器语法
  const decoratorPatterns = ['@Entry', '@Component', '@Builder'];
  decoratorPatterns.forEach(pattern => {
    const regex = new RegExp(pattern, 'g');
    const matches = content.match(regex);
    console.log(`${pattern} 装饰器出现次数:`, matches ? matches.length : 0);
  });
  
} catch (error) {
  console.error('错误:', error.message);
}